function z = agm(x,y,it)

a = 0.5*(x+y);
g = sqrt(x*y);

for i=1:it
    at = a;
    a = 0.5 * (a+g);
    g = sqrt(at*g);
end; 
    
z = a;
